package com.ruoyi.web.controller.bank;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bank.domain.BankGreyRegister;
import com.ruoyi.bank.service.IBankGreyRegisterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 灰名册管理Controller
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/bank/grey")
public class BankGreyRegisterController extends BaseController
{
    @Autowired
    private IBankGreyRegisterService bankGreyRegisterService;

    /**
     * 查询灰名册管理列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BankGreyRegister bankGreyRegister)
    {
        startPage();
        List<BankGreyRegister> list = bankGreyRegisterService.selectBankGreyRegisterList(bankGreyRegister);
        return getDataTable(list);
    }

    /**
     * 导出灰名册管理列表
     */

    @Log(title = "灰名册管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BankGreyRegister bankGreyRegister)
    {
        List<BankGreyRegister> list = bankGreyRegisterService.selectBankGreyRegisterList(bankGreyRegister);
        ExcelUtil<BankGreyRegister> util = new ExcelUtil<BankGreyRegister>(BankGreyRegister.class);
        util.exportExcel(response, list, "灰名册管理数据");
    }
    @Log(title = "灰名册管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BankGreyRegister> util = new ExcelUtil<BankGreyRegister>(BankGreyRegister.class);
        List<BankGreyRegister> greyList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = bankGreyRegisterService.importGrey(greyList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<BankGreyRegister> util = new ExcelUtil<BankGreyRegister>(BankGreyRegister.class);
        util.importTemplateExcel(response, "灰名册数据");
    }
    /**
     * 获取灰名册管理详细信息
     */

    @GetMapping(value = "/id/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(bankGreyRegisterService.selectBankGreyRegisterByCustomerId(customerId));
    }
    /**
     * 获取灰名册管理详细信息
     */
    @GetMapping(value = "/number/{customerNumber}")
    public AjaxResult getNumber(@PathVariable("customerNumber") String customerNumber)
    {
        return success(bankGreyRegisterService.selectBankGreyRegisterByCustomerNumber(customerNumber));
    }
    /**
     * 新增灰名册管理
     */

    @Log(title = "灰名册管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BankGreyRegister bankGreyRegister)
    {
        return toAjax(bankGreyRegisterService.insertBankGreyRegister(bankGreyRegister));
    }

    /**
     * 修改灰名册管理
     */

    @Log(title = "灰名册管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BankGreyRegister bankGreyRegister)
    {
        return toAjax(bankGreyRegisterService.updateBankGreyRegister(bankGreyRegister));
    }

    /**
     * 删除灰名册管理
     */

    @Log(title = "灰名册管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(bankGreyRegisterService.deleteBankGreyRegisterByCustomerIds(customerIds));
    }
}
